#ifndef WIDGET_H
#define WIDGET_H

#include <QMetaEnum>
#include <QTimer>
#include <QWidget>
#include <map>

#include <arpa/inet.h>
#include <cstring>
#include <iostream>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>


QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE

/**
 * @brief 用socket，实现udp通信服务端
 */
class Widget : public QWidget {
  Q_OBJECT

public:
  Widget(QWidget *parent = nullptr);
  ~Widget();

  void onDisconnected();

private slots:
  void on_btnStart_clicked();
  void onReadyRead();
  void on_btnSend_clicked();

private:
  Ui::Widget *ui;
  int m_udpServer;
  bool m_start = false;
  QTimer m_timer;

  std::map<std::string ,struct sockaddr_in > m_clientList; ///< 所有客户端
};
#endif // WIDGET_H
